//收货地址
var t = getApp(),
  //info=t.getCache("userinfo"),
  e = t.requirejs("core");
Page({
  data: {
    route: "member_address",
    menu: t.tabBar,
    menu_show: false,
    loaded: !1,
    list: []
  },
  //底部导航跳转
  menu_url: function (k) {
    e.menu_url(k, 2);
  },
  onLoad: function (options) {

    if (options != null && options != undefined) {
      this.setData({
        tabbar_index: options.tabbar_index ? options.tabbar_index : -1
      });
    }

    e.setting();
    "" == t.getCache("userinfo") && (e.toast('您还没登录呢'),
      setTimeout(function () {
        wx.redirectTo({
          url: "/yb_mingpian/pages/index/index"
        })
      }, 1e3));
    this.setData({
      menu: getApp().tabBar,
      config: getApp().config
    })

    if (this.data.tabbar_index >= 0) {
      this.setData({
        showtabbar: getApp().tabBar.IsDiDis ? getApp().tabBar.IsDiDis : false,
      })
    }
        
  },
  onShow: function () {
    this.getList()
  },
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh()
  },
   /**
* 获取收货地址列表
*/
  getList: function () {
    var t = this;
    e.get("user/AddressList", { uid: getApp().getCache("userinfo").uid}, function (i) {
      if(i.code==0){
        t.setData({
          loaded: !0,
          list: i.info,
          show: !0
        })
      }else{
        t.setData({
          loaded: !0,
          list: [],
          show: !0
        })
      }
    })
  },
  
   /**
* 设置默认地址
*/
  setDefault: function (t) {
    var s = this,
      i = e.pdata(t).id;
    s.setData({
      loaded: !1
    }),
      e.get("user/UpdateAddress", {
        id: i,
        uid: getApp().getCache("userinfo").uid,
        is_default:1
      }, function (t) {
        if (0 != t.code)
          return s.setData({
            posting: false
          }), void a.toast(s, t.msg);
        e.toast("设置成功"),
          s.getList()
      })
  },
    /**
* 删除收货地址
*/
  deleteItem: function (t) {
    var s = this,
      i = e.pdata(t).id;
    e.confirm("删除后无法恢复, 确认要删除吗 ?", function () {
      s.setData({
        loaded: !1
      }),
        e.get("user/DelAddress", {
          id: i
        }, function (t) {
          if (0 != t.code)
            return s.setData({
              posting: false
            }), void a.toast(s, t.msg);
          getApp().removeCache("orderAddress"),
          e.toast("删除成功"),
            s.getList()
        })
    })
  }
})